<?php

namespace module\app\controller;

use app\Controller;
use app\model\UserVip as Model;

class UserVip extends Controller
{
    /**
     * 列表.
     * 
     */
    public function index()
    {
        $result = Model::scope('user')->field(['level', 'status'])->with('user')->withSearch(['status', 'level'], input('get.'))->scope('user')->order('create_at', 'DESC')->paginate([
            'list_rows'=> input('get.pageSize/d', 10),
        ]);
        return json([
            'items' => $result->items(),
            'total' => $result->total()
        ]);
    }
    /**
     * 详情.
     * 
     * @param int $id
     */
    public function read(int $id)
    {
        $model = Model::scope('user')->with('relates')->field(['user_id', 'level', 'status'])->with('user')->findOrFail($id);
        return json($model->toArray());
    }
    /**
     * 更新.
     * 
     * @param int $id
     */
    public function update(int $id)
    {
        $model = Model::scope('user')->findOrFail($id);
        $model->save($this->request->put());
        return json($model->toArray());
    }
}
